<?php


class template extends Abstructtemplate{
	
	private $templateObj;
	const templateExt = ".tpl";
	const templateFk  = "template_framework";
	
	public function __construct(){
		/* @var $GO_RES _CNRES*/
		global $GO_RES;
		require_once(getcwd().DIRECTORY_SEPARATOR."lib".DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR."smarty".DIRECTORY_SEPARATOR."Smarty.class.php"); //Smarty解析类
		$this->templateObj = new Smarty;
		$this->templateObj->template_dir = getcwd().DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR;
		$this->templateObj->compile_dir  = getcwd().DIRECTORY_SEPARATOR.'uploadfile'.DIRECTORY_SEPARATOR.'templates_c'.DIRECTORY_SEPARATOR;	
		$this->templateObj->assign("init_appName",_cfg::appName);
		$this->templateObj->assign_by_ref("res",$GO_RES);
		if(isset($_SESSION[_cfg::sessionPrefix."__uid"]) && is_array($_SESSION[_cfg::sessionPrefix."__uid"])){
			$this->templateObj->assign("init_logined",1);	
		}
	}
	
	public function assign($key,$value){
		$this->templateObj->assign($key,$value);
	}
	
	public function display($template,$tag=true){
		if(file_exists(getcwd().DIRECTORY_SEPARATOR."templates".DIRECTORY_SEPARATOR."header".DIRECTORY_SEPARATOR.$template.self::templateExt)){
			$this->templateObj->assign("_loadheader",1);
		}
		$template = $tag?$template:$template."_fail";
		$this->templateObj->assign("so",$template);
		$this->templateObj->assign("webUrl",_cfg::wegUrl);
		$this->templateObj->assign("tpl",$template.self::templateExt);
		$this->templateObj->display(self::templateFk.self::templateExt);
	}
	
	public function test($template){
		$this->display($template);
	}
}

return md5(__FILE__);